﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;

namespace ADS2Excel
{
    class SymbolConfig
    {
        public enum Flag_Direction { R, L };
        public static List<SymbolADSInfo> GetSymbolADS(Flag_Direction f)
        {
            var config = System.Configuration.ConfigurationManager.GetSection("SymbolADSSection") as SymbolADSSection;
            var col = new List<SymbolADSInfo>();
            if (config != null)
            {
                if (f == Flag_Direction.L)
                {
                    foreach (SymbolADSInfo temp in config.SymbolADSL)
                    {
                        col.Add(new SymbolADSInfo { SymbolADSName = temp.SymbolADSName, SymbolADSLength = temp.SymbolADSLength });
                    }
                }
                else
                {
                    foreach (SymbolADSInfo temp in config.SymbolADSR)
                    {
                        col.Add(new SymbolADSInfo { SymbolADSName = temp.SymbolADSName, SymbolADSLength = temp.SymbolADSLength });
                    }
                }

            }

            return col;
        }
    }
    public class SymbolADSInfo : ConfigurationElement
    {
        [ConfigurationProperty("name", IsRequired = true)]
        public string SymbolADSName
        {
            get { return (string)base["name"]; }
            set { base["name"] = value; }
        }

        [ConfigurationProperty("length", IsRequired = true)]
        public int SymbolADSLength
        {
            get { return (int)base["length"]; }
            set { base["length"] = value; }
        }

    }

    public class SymbolADSCollection : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new SymbolADSInfo();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            var ep = (SymbolADSInfo)element;
            return ep.SymbolADSName;
        }
    }

    public class SymbolADSSection : ConfigurationSection
    {
        [ConfigurationProperty("SymbolADSL", IsRequired = false)]
        public SymbolADSCollection SymbolADSL
        {
            get { return (SymbolADSCollection)base["SymbolADSL"]; }
        }

        [ConfigurationProperty("SymbolADSR", IsRequired = false)]
        public SymbolADSCollection SymbolADSR
        {
            get { return (SymbolADSCollection)base["SymbolADSR"]; }
        }
    }
}
